package com.accesshollywood.speech;

import com.accesshollywood.trace.Trace;
import com.sun.speech.freetts.Voice;
import com.sun.speech.freetts.VoiceManager;

public class Speak {
	private static final String	VOICENAME	= "kevin16";
	// private static final String VOICENAME = "kevin";
	// private static final String VOICENAME = "alan";
	private static Voice		voice;

	public Speak() {

	}

	public static void setup() {
		System.setProperty("freetts.voices", "com.sun.speech.freetts.en.us.cmu_us_kal.KevinVoiceDirectory");
		System.setProperty("FreeTTSSynthEngineCentral","com.sun.speech.freetts.jsapi.FreeTTSEngineCentral");
		VoiceManager voiceManager = VoiceManager.getInstance();
		//Trace.info (System.getProperty ("user.home"));
		//Trace.info (System.getProperty ("java.home"));
		Voice[] voices = voiceManager.getVoices();

		voice = voiceManager.getVoice(VOICENAME);
		if (voice != null) {
			voice.allocate();
			//voice.speak("Welcome to the Access Hollywood Graphics ordering system.");
		} else {
			//Trace.info("Crap, no voices.");
		}
	}

	public static void say(String str) {
		if (voice != null) {
			voice.speak(str);
		}
	}

	public static void spell(String str) {
		for (int i = 0; i < str.length(); i++) {
			char character = str.charAt(i);
			if (character == 'a' || character == 'A') {
				say("Ayy");
			} else if (character == 'e' || character == 'E') {
				say("Eee");
			} else if (character == 'i' || character == 'I') {
				say("Eye");
			} else if (character == 'o' || character == 'O') {
				say("Oh");
			} else if (character == 'u' || character == 'U') {
				say("You");
			} else if (character == 'y' || character == 'Y') {
				say("Why");
			} else if (character == ' ') {
				say("space");
			} else {
				say(Character.toString(str.charAt(i)));
			}
		}
	}
}
